/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package muddb.entities;

import java.io.Serializable;
import javax.persistence.Column;
import javax.persistence.EmbeddedId;
import javax.persistence.Entity;
import javax.persistence.IdClass;
import javax.persistence.JoinColumn;
import javax.persistence.JoinColumns;
import javax.persistence.ManyToOne;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.Table;


/**
 *
 * @author keith
 */
@Entity
@Table( name = "skill_group_prof" )
@NamedQueries(
  {
    @NamedQuery( name = "SkillGroupProf.findByUserId",
                  query = "SELECT s FROM SkillGroupProf s WHERE s.skillGroupProfPK.userId = :userId" ),
    @NamedQuery( name = "SkillGroupProf.findByCharId",
                  query = "SELECT s FROM SkillGroupProf s WHERE s.skillGroupProfPK.charId = :charId" ),
    @NamedQuery( name = "SkillGroupProf.findBySkillGrpId",
                  query = "SELECT s FROM SkillGroupProf s WHERE s.skillGroupProfPK.skillGrpId = :skillGrpId" ),
    @NamedQuery( name = "SkillGroupProf.findByProf",
                  query = "SELECT s FROM SkillGroupProf s WHERE s.prof = :prof" )
} )
public class SkillGroupProf implements Serializable {
  private static final long serialVersionUID = 1L;
  protected SkillGroupProfPK skillGroupProfPK;
  
  private Short prof;
  
  private SkillGroup skillGroup;
  
  private UserChar userChar;


  public SkillGroupProf() {
  }


  public SkillGroupProf( SkillGroupProfPK skillGroupProfPK ) {
    this.skillGroupProfPK = skillGroupProfPK;
  }


  public SkillGroupProf( int userId, int charId, int skillGrpId ) {
    this.skillGroupProfPK = new SkillGroupProfPK( userId, charId, skillGrpId );
  }


  @EmbeddedId
  public SkillGroupProfPK getSkillGroupProfPK() {
    return skillGroupProfPK;
  }


  public void setSkillGroupProfPK( SkillGroupProfPK skillGroupProfPK ) {
    this.skillGroupProfPK = skillGroupProfPK;
  }




  @Column( name = "prof" )
  public Short getProf() {
    return prof;
  }


  public void setProf( Short prof ) {
    this.prof = prof;
  }




  @JoinColumn( name = "skill_grp_id", referencedColumnName = "skill_grp_id",
              insertable = false, updatable = false)
  @ManyToOne
  public SkillGroup getSkillGroup() {
    return skillGroup;
  }


  public void setSkillGroup( SkillGroup skillGroup ) {
    this.skillGroup = skillGroup;
  }




  @JoinColumns(
    {
      @JoinColumn( name = "user_id", referencedColumnName = "user_id",
                    insertable = false, updatable = false ),
      @JoinColumn( name = "char_id", referencedColumnName = "char_id",
                    insertable = false, updatable = false )
    }
  )
  @ManyToOne
  public UserChar getUserChar() {
    return userChar;
  }


  public void setUserChar( UserChar userChar ) {
    this.userChar = userChar;
  }


  @Override
  public int hashCode() {
    int hash = 0;
    hash += ( skillGroupProfPK != null ? skillGroupProfPK.hashCode() : 0 );
    return hash;
  }


  @Override
  public boolean equals( Object object ) {
    // TODO: Warning - this method won't work in the case the id fields are not set
    if ( !( object instanceof SkillGroupProf ) ) {
      return false;
    }
    SkillGroupProf other = (SkillGroupProf) object;
    if ( ( this.skillGroupProfPK == null && other.skillGroupProfPK != null ) || ( this.skillGroupProfPK != null && !this.skillGroupProfPK.equals( other.skillGroupProfPK ) ) ) {
      return false;
    }
    return true;
  }


  @Override
  public String toString() {
    return "muddb.entities.SkillGroupProf[skillGroupProfPK=" + skillGroupProfPK + "]";
  }

}
